const {
  USER_NAME_OR_PASS_WORD,
  USER_NAME_OR_PASSWORD_ERROR,
  TOKEN_SHIXIAO,
  USER_NAME_IS_COPY,
  IS_AUTHOR,
  IS_NOT_MOMONET
} = require("../contants/error-type")

const userError = ((err, req, res, next) => {
  console.log(err.message, "ooo")

  let status, message;
  switch (err.message) {
    // 测试用的
    case USER_NAME_OR_PASS_WORD: 
      status = 400;
      message = "用户名或密码错误";
      break;
    case USER_NAME_IS_COPY:
      status = 403;
      message = "用户名重复";
      break;
    case USER_NAME_OR_PASSWORD_ERROR:
      status = 400;
      message = "不存在该用户,请注册";
      break;
    case TOKEN_SHIXIAO:
      status = 401;
      message =  "token失效了";
      break;
    case IS_AUTHOR:
      status = 402;
      message = "不可修改别人的评论";
      break;
    case IS_NOT_MOMONET:
      status = 400;
      message = "该用户没有权限进行此操作";
      break;
    default: 
      status = 500;
      message = "服务器错误"
  }
  res.json({
    status,
    errmsg: message
  })
  // res.json({
  //   errmsg: err.message
  // })
});



module.exports = {
  userError
}